package com.example.demo.dao;

import com.example.demo.model.ArticleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-16
 * Time: 16:52
 */
public interface ArticleMapper {
      @Select("select * from articleinfo where uid = #{id} order by createtime desc")
      List<ArticleInfo> getListByUid(@Param("id") int id);

      @Delete("delete from articleinfo where id = #{id} and uid = #{uid}")
      int del(@Param("id") Integer id,@Param("uid") Integer uid);

      @Insert("insert into articleinfo(title,content,uid) values(#{title},#{content},#{uid})")
      int add(ArticleInfo articleInfo);

      @Select("select * from articleinfo where id=#{aid}")
      ArticleInfo getArticleByidAnduid(@Param("aid") int aid,@Param("uid") int uid);

      @Update("update articleinfo set title=#{title},content=#{content}" +
              ",updatetime=#{updatetime} where id = #{id} and uid = #{uid}")
      int update(ArticleInfo articleInfo);

      @Select("select * from articleinfo where id=#{aid}")
      ArticleInfo getArticleById(@Param("aid") int aid);

      @Select("select count(*) from articleinfo where uid = #{uid};")
      int getArtCount(@Param("uid") int uid);

      @Update("update articleinfo set rcount=rcount+1 where id=#{aid}")
      int increRcount(@Param("aid") int aid);

      @Select("select * from articleinfo order by createtime desc limit #{finalLimit} offset #{finalOffset}")
      List<ArticleInfo> getListByPage(@Param("finalLimit") int finalLimit,@Param("finalOffset") int finalOffset);

      @Select("select count(*) from articleinfo")
      int getCount();

}
